package com.tjvib.util.retrofit;

import com.tjvib.util.LogUtil;
import com.tjvib.util.Manager.AppManager;
import com.tjvib.util.ToastUtil;

import retrofit2.Call;
import retrofit2.Callback;

/**
 * 统一处理错误码
 *
 * @param <T>
 */
public abstract class RetrofitCallback<T> implements Callback<T> {
    @Override
    public void onFailure(Call<T> call, Throwable t) {
        if (t instanceof ApiException) {
            ApiException apiException = (ApiException) t;
            if (apiException.isTokenExpried()) {
                LogUtil.e("TOKEN失效");
                ToastUtil.show("您长时间未使用，请重新登录");
                AppManager.getInstance().exitApp();
            } else if (apiException.isFailed()) {
                ToastUtil.show(apiException.getMessage());
                LogUtil.e("失败" + apiException.getMessage());
            }
        }
    }
}

